﻿using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Lib.Common;
using Microsoft.ApplicationBlocks.Data;
using Module.EntitiesInfo;

namespace Module.DataAccess
{
    public class CategoryDB
    {
        #region ConnectionString
        private string _connectionString;
        public string ConnectionString
        {
            get { return _connectionString; }
            set { _connectionString = value; }
        }
        public CategoryDB()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings["localsql"].ToString();
        }
        #endregion

        public virtual DataTable GetAll()
        {
            DataTable dt = SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure, "Category_GetAll").Tables[0];
            return dt;
        }
        public virtual void Delete(int id)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@Id", id)
			};
            SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "Category_Delete", parameters);
           
        }
        public virtual int Insert(string title, double rate)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
				new SqlParameter("@Title", title),
				new SqlParameter("@Rate", rate)
			};
            return (int)SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "Category_Insert", parameters);
        }

        public virtual void Update(int id, string title, double rate)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@Id", id),
                new SqlParameter("@Title", title),
				new SqlParameter("@Rate", rate)								
			};
            SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "Category_Update", parameters);
        }

        public virtual IDataReader GetInfo(int id)
        {            
           SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@Id", id)							
			};
          return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, "Category_GetInfo", parameters);
        }

    }
}

